<template>
    <div class="black_board_bg_container">
        <div>黑板背景颜色</div>
        <div class="item_group">
            <div :class="['paint_brush_color', index == activeBg ? 'activeColor' : '']"
                v-for="(item, index) in blackBoardBgColor" :style="{ background: item }"
                @click="clickButtonHandler('bgColor', item, index)"></div>
        </div>
        <div>黑板背景图片</div>
        <div class="item_group">
            <img class="black_board_bg_image" :src="item" alt="" v-for="(item, index) in blackBoardBgImage"
                @click="clickButtonHandler('bgImage', item, index)">
        </div>
    </div>
</template>

<script setup lang='ts'>
import { activeBg, blackBoardBgColor, blackBoardBgImage } from './data';

const emits = defineEmits(["clickPaintBrushBtn"])

const clickButtonHandler = (type: string, item?: string, index?: number) => {
    const objectHandler: Record<string, () => void> = {
        bgColor: () => {
            emits("clickPaintBrushBtn", "bgColor", item, index);
        },
        bgImage: () => {
            emits("clickPaintBrushBtn", "bgImage", item, index);
        },
    }

    objectHandler[type]()
}
</script>

<style scoped lang="scss">
.black_board_bg_container {
    position: absolute;
    left: 125px;
    top: 210px;
    padding: 10px;
    margin: 0;
    box-shadow: 2px 2px 10px 1px rgba(18, 18, 20, 0.38);
    background-color: #fff;
    border-radius: 8px;
    width: 250px;

    .item_group {
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        margin: 15px 0;

        .paint_brush_color {
            width: 25px;
            height: 25px;
            border-radius: 50%;
        }

        .activeColor {
            position: relative;
            border: 1px solid transparent;

            &::before {
                content: "";
                position: absolute;
                width: 14px;
                height: 14px;
                top: 3px;
                left: 3px;
                border-radius: 50%;
                border: 3px solid #eee;
            }
        }

        .black_board_bg_image {
            width: 40px;
            height: 40px;
        }
    }
}
</style>